package com.spring.shops.admin.controller.shop;

import com.spring.shops.dao.TzNoticeMapper;
import com.spring.shops.model.dto.NoticeDTO;
import com.spring.shops.model.entity.TzNotice;
import com.spring.shops.model.result.IPageIndexImg;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.NoticeVo;
import com.spring.shops.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;


    @GetMapping("/page")
    public ServerResponseEntityVoid<IPageIndexImg<NoticeVo>> page(
            NoticeDTO noticeDTO){
        return noticeService.page(noticeDTO);
    }

    @GetMapping("/info/{id}")
    public ServerResponseEntityVoid getInfoById(@PathVariable Long id){
        TzNotice tzNotice = noticeService.selectById(id);
        return ServerResponseEntityVoid.success(tzNotice);
    }

    @DeleteMapping("/{id}")
    public ServerResponseEntityVoid deleteInfoById( @PathVariable Long id){
         noticeService.deletedById(id);
            return ServerResponseEntityVoid.success();

    }
    @PostMapping
    public ServerResponseEntityVoid saveInfo(@RequestBody TzNotice tzNotice){
        System.out.println(tzNotice.getContent());
        int save = noticeService.save(tzNotice);
        return ServerResponseEntityVoid.success(save);
    }

    @PutMapping
    public ServerResponseEntityVoid update(@RequestBody  TzNotice tzNotice){
         noticeService.update(tzNotice);
        return ServerResponseEntityVoid.success();
    }












}
